package com.jw.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jw.response.Result;
import com.jw.system.entity.Goods;
import com.jw.system.entity.vo.GoodsInVO;
import com.jw.system.entity.vo.GoodsOutVO;
import com.jw.system.entity.vo.GoodsVO;
import com.jw.system.service.GoodsInService;
import com.jw.system.service.GoodsOutService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品出库表 前端控制器
 * </p>
 *
 * @author jw
 * @since 2021-04-28
 */
@RestController
@RequestMapping("/goods-out")
public class GoodsOutController {

    @Autowired
    private GoodsOutService goodsOutService;

    /**
     * 获取商品发货列表
     *
     * @return
     */
    @ApiOperation(value = "发货列表", notes = "模糊查询发货列表")
    @PostMapping("/getGoodsOutList")
    public Result getGoodsOutList(@RequestParam(value = "current", required = false) Integer current,
                                 @RequestParam(value = "size", required = false) Integer size,
                                 @RequestParam(value = "audit", required = false) Boolean audit,
                                 @RequestBody GoodsOutVO goodsOutVO) {
        Page<GoodsOutVO> goodsOutList = goodsOutService.getGoodsOutList(current, size, audit,goodsOutVO);
        return Result.ok().data("goodsOut", goodsOutList.getRecords()).data("total", goodsOutList.getTotal());
    }

    /**
     * 新增入库单
     */
    @ApiOperation(value = "添加出库")
    @PostMapping("/add")
    public Result add(@RequestBody GoodsOutVO goodsOutVO) {
        goodsOutService.add(goodsOutVO);
        return Result.ok();
    }

    /**
     * 新增入库单
     */
    @ApiOperation(value = "完成发货")
    @PostMapping("/finish")
    public Result finish(@RequestBody GoodsOutVO goodsOutVO) {
        goodsOutService.finish(goodsOutVO);
        return Result.ok();
    }

    /**
     * 发货单详细
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "入库单明细")
    @GetMapping("/getDetail")
    public Result detail(@RequestParam(value = "id") Long id,
                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                         @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        Page<GoodsVO> goodsList = goodsOutService.getDetail(pageNum, pageSize, id);
        return Result.ok().data("goods", goodsList.getRecords()).data("total", goodsList.getTotal());
    }


    /**
     * 发货审核
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "入库审核")
    @GetMapping("/getApprove")
    public Result getApprove(@RequestParam(value = "id") Long id) {
        goodsOutService.getApprove(id);
        return Result.ok();
    }

}

